"""
## 课后作业
- 通过`datetime`模块完成时间戳, `datetime.datetime`对象, 格式化字符串三者之间的转换
- 封装一个函数`get_date(day_delta)`, 如果传入的是`-1` , 输出就是字符串日期`2020-01-02`.

"""
from datetime import datetime, timedelta

"""
 `datetime.datetime` -> `str`
"""
now = datetime.now(tz=None)
print(now)
print(type(now))
str_now = now.strftime("%Y/%m/%d %H:%M:%S")
print(str_now)

"""
`str`  -> `datetime.datetime`
"""
now2 = datetime.strptime(str_now, "%Y/%m/%d %H:%M:%S")
print(now2)
print(type(now2))

"""
`datetime.datetime` -> `timestamp`
"""
now3 = datetime.now(tz=None)
time_stamp = now3.timestamp()
print(time_stamp)

"""
`timestamp` -> `datetime.datetime`
"""
now4 = datetime.fromtimestamp(time_stamp, tz=None)
print(now4)


def get_date(day_delta):
    return datetime.now() + timedelta(days=day_delta)

print(get_date(5))
